package com.sqkj.service;

import com.sqkj.dao.UserDao;
import com.sqkj.entity.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserService {
    @Resource
    UserDao dao;

    public List<User> findByName(String UserName) {
        return  dao.findByName(UserName);
    }
    public List<User> findAll(){
        return dao.findAll();
    }
    public User findById(int id){
        return dao.findById(id);
    }

    public User findByWxName(String wxName) {
        return dao.findByWxName(wxName);
    }
    public User findByOpenId(String openId) {
        return dao.findByOpenId(openId);
    }

    public Boolean isExistUser(String wxName) {
        if (dao.findByWxName(wxName) != null) {
            return true;
        } else {
            return false;
        }
    }
    public Boolean isExistUser2(String opendId) {
        if (dao.findByOpenId(opendId) != null) {
            return true;
        } else {
            return false;
        }
    }
    public Boolean UserCount(String UserCount) {
        if(dao.UserCount(UserCount)<=0 || dao.UserCount(UserCount)>1){
            return false;
        }else {
            return true;
        }

    }
    @Transactional
    public Boolean add(User user){
        if (dao.add(user)>0){
            return true;
        }else {
            return false;
        }

    }
    @Transactional
    public Boolean deleteById(int id){
        if (dao.deleteById(id)>0){
            return true;
        }else {
            return false;
        }
    }
    @Transactional
    public Boolean upDate(User user){
        if(dao.update(user)>0){
            return true;
        }else {
            return false;
        }

    }
    public List<User> like (String str){
        List<User> list = dao.findLike(str);



        return list;
    }

    public Boolean findByName2(String UserName) {
        if (!dao.findByName(UserName).isEmpty()) {
            return true;
        } else {
            return false;
        }
    }

}
